--[[

Copyright (c) 2012-2013 baby-bus.com

http://www.babybus.com/superdo/

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

]]

--[[!--

框架[盒子]场景类，定义框架场景类公用操作方法及逻辑实现。

-   定义框架场景相关信息。

]]

----------------------
-- 类
----------------------
local M     = classScene("FBoxScene")


----------------------
-- 公共参数
----------------------
-- [常量]
-- ..

-- [操作变量]
-- ..








----------------------
-- 私有方法
----------------------
-- 获得模块名称
local function getModuleName(name)
	return S.subbl(name, NAMING_SCENE)
end








----------------------
-- 构造方法
----------------------
--[[--

构造方法，定义结点实例初始化逻辑

### Useage:

### Parameters:
-   table **properties**    参数集合

### Returns: 
-   object                  类实例

--]]--
function M:ctor(params)
	-- [超类调用]
	M.super.ctor(self, params)
end








----------------------
-- 模板方法
----------------------
--[[--

加载层

### Useage:
	local self = FScene:loadLayer(层名称[, 层深度, 层实例化参数])

### Aliases:
    
### Notice:
	通过FScene:getLayerNames()方法创建的层默认以层深度10开始，按顺序间隔10层深度增长
	如：return "background", "main", "button"，则：background为10，main为20，button为30

### Example:
    ----------------------
    -- 示例1: 通用操作
    ----------------------
    -- 加载层介于背景层和主场景层之间
    scene:loadLayer("backgroundEffect", 15, { someArg = "Anything" })

### Parameters:
-   string **layerName**    层名称
-   number **z**    		层深度
-   table **args**    		层实例化参数

### Returns: 
-   object              	自身

--]]--
function M:loadLayer(layerName, z, args)
	-- [参数默认]
	args 				= ifnil(args, {})
	args.priority 		= -z

	-- [实例创建]
	-- 模块名称
	local moduleName 	= getModuleName(self.name)
	-- 层名称
	local layerName  	= S.ucfirst(layerName) .. "Layer"
	-- 实例化
	local layer 		= require(string.format("app.box.%s.layer.%s", S.lower(moduleName), layerName)).new(args)
	-- 追加属性
	layer.moduleName 	= moduleName
	-- 添加到场景
	layer:to(self, ifnil(z, 0))

	-- [记录状态]
	self:bindProperty(layerName)
	self:setProperty(layerName, layer)

	return self
end

-- 返回键
function M:onKeypadBackHandler()     
    self:exitApp()   
end


function M:exitApp()
    if not self.touchTimes then 
    	self.touchTimes = 0 
    end
    self.touchTimes = self.touchTimes + 1

    self:stopAllActions()
    if self:isPopTip() then
        self:removePopTip()
    elseif self.touchTimes >= 2 then
        NV.exit()
    else
        A.line({
            {"fn", handler(self, self.oneMoreTime)},
            {"delay", 2.0},
            {"fn", function() self.touchTimes = 0 end},
        }):at(self)
    end
end

--[[--

是否进行资源自动清理[图像]

### Useage:
	local isCleanup = FScene:isAutoCleanupImages()

### Aliases:
    
### Notice:

### Example:

### Parameters:

### Returns: 
-   bool              		深度调度清理标识

--]]--
function M:isAutoCleanupImages()
	return true
end



return M